const webpack = require('webpack')
const path = require('path');
const PrerenderSPAPlugin = require('prerender-spa-plugin');
const Renderer = PrerenderSPAPlugin.PuppeteerRenderer;

// const createThemeColorReplacerPlugin = require('./config/plugin.config')

function resolve (dir) {
  return path.join(__dirname, dir)
}

// vue.config.js
const vueConfig = {
  configureWebpack: {
    plugins: [
      // Ignore all locale files of moment.js
      new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
      
      // new PrerenderSPAPlugin({
      //   staticDir:path.join(__dirname, 'dist'),
      //   routes:['/'],
        // renderer: new Renderer({
          // renderAfterDocumentEvent: 'render-event'
        // }),
      // })

      new PrerenderSPAPlugin({
        staticDir: path.join(__dirname, 'dist'), // 生成的静态文件目录
        routes: ['/'], // 需要预渲染的路由
        renderer: new Renderer({
          headless: true, // 无头模式
          inject: {
            foo: 'bar', // 如果需要的话，可以在这里注入变量
            enderAfterDocumentEvent: 'render-event',
            // renderAfterTime: 5000
          },
        })
      })

      
    ]
  },

  chainWebpack: (config) => {
    config.resolve.alias
      .set('@$', resolve('src'))

    const svgRule = config.module.rule('svg')
    svgRule.uses.clear()
    svgRule
      .oneOf('inline')
      .resourceQuery(/inline/)
      .use('vue-svg-icon-loader')
      .loader('vue-svg-icon-loader')
      .end()
      .end()
      .oneOf('external')
      .use('file-loader')
      .loader('file-loader')
      .options({
        name: 'assets/[name].[hash:8].[ext]'
      })
  },

  css: {
    loaderOptions: {
      less: {
        modifyVars: {
          // less vars，customize ant design theme

          // 'primary-color': '#F5222D',
          // 'link-color': '#F5222D',
          // 'border-radius-base': '4px'
          'menu-dark-submenu-bg': '#1C2D57',
          'menu-dark-bg': '#1C2D57',
          'layout-sider-background': '#1C2D57',
          'menu-item-active-bg': '#152347',
          'menu-dark-item-active-bg': '#152347',
          'menu-dark-arrow-color': '#508dc8',
          'menu-dark-color': '#aabde4',
          'menu-dark-highlight-color': '#508dc8'
        },
        javascriptEnabled: true
      }
    }
  },
  devServer: {
    // development server port 8000
    port: 8000,
    // If you want to turn on the proxy, please remove the mockjs /src/main.jsL11
    proxy: {
      '/userdatacenter': {
        target: 'http://auth.test.paas.gwm.cn',
        ws: false,
        changeOrigin: true,
        pathRewrite: {
          '^/userdatacenter': ''
        }
      },
    }
  },
  
  // disable source map in production
  productionSourceMap: false,
  lintOnSave: undefined,
  // babel-loader no-ignore node_modules/*
  transpileDependencies: []
}

// preview.pro.loacg.com only do not use in your production;
// if (process.env.NODE_ENV !== 'production' || process.env.VUE_APP_PREVIEW === 'true') {
//   // add `ThemeColorReplacer` plugin to webpack plugins
//   vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
// }

module.exports = vueConfig
